package com.yangye.springclouddemoredis.controller;

import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangye
 * @date 2020/08/03
 */
@RestController
public class TestSentinelController {
	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	@RequestMapping("/sentinel/test")
	void testSentinel() throws InterruptedException {
		int i = 0;
		while (true) {
			stringRedisTemplate.opsForValue().set("test-sentinel-" + i, i + "");
			i++;
			Thread.sleep(1000);
		}
	}

	@RequestMapping("/cluster/test")
	String testCluster() throws InterruptedException {
		stringRedisTemplate.opsForValue().set("test-cluster", "test");
		return stringRedisTemplate.opsForValue().get("test-cluster");
	}
}
